from rest_framework import serializers
from .models import *


# 订单信息的序列化器
class OrderInfoSer(serializers.ModelSerializer):
    # 获取用户名
    user_name = serializers.SerializerMethodField(read_only=True)

    def get_user_name(self, obj):
        return obj.user.username

    # 获取支付状态的信息
    status_name = serializers.SerializerMethodField(read_only=True)

    def get_status_name(self, obj):
        return obj.get_status_display()

    class Meta:
        model = OrderInfo
        fields = "__all__"
        read_only_fields = ["order_id",]


# 订单商品的序列化器
class OrderGoodsSer(serializers.ModelSerializer):

    class Meta:
        model = OrderGoods
        fields = "__all__"
        read_only_fields = ['id',]



